﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using CheatMenu.Utils;
using CheatMenu.Managers;
using UnityEngine.SceneManagement;

namespace CheatMenu.Menus
{
    public class MenuLoadScene : MenuButtonList
    {
        private readonly string[] blacklistScenes = { "intro01", "house1", "Start", "start_day" };

        public MenuLoadScene() : base("LoadScene", null)
        {
            Alignment = Alignment.Centre;
            HeaderText = "EXPERIMENTAL";
            string[] sceneNames = SceneUtil.GetSceneNames();
            sceneNames = sceneNames.Where((s) => !blacklistScenes.Contains(s)).ToArray();
            CommandGroup groupScenes = new CommandGroup("Scenes");

            //sceneNames = sceneNames.Where((s) => !blacklistScenes.Contains(s)).OrderBy((s) => s).ToArray();
            for (int i = 0; i < sceneNames.Length; i++)
            {
                string sceneName = sceneNames[i];
                groupScenes.AddCommand(sceneName, (c) => LoadScene(sceneName));
            }
            CommandGroups.Add(groupScenes);
        }

        private void LoadScene(string sceneName)
        {
            SceneManager.LoadScene(sceneName);
            if(GUIManager.AutoCloseLoadScene)
                Shown = false;
        }

        protected override Vector2 InitializeSize()
        => new Vector2((GUIManager.ControlHeight * 10f) + (GUIManager.PaddingSize * 2) + GUIManager.ScrollBarWidth, (GUIManager.ControlHeight * 15) + (GUIManager.PaddingSize * 2));
    }
}
